/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exercises.day01.pt2;

import javax.swing.JOptionPane;

/**
 * MyFirstJava
 *
 * @author (jaice)
 * @version 0.1 (may 28, 2012)
 * 
 *c. Write a program to print rainfall statistics.  This program will read a series 
 *of rainfall measurements (number of millimeters of rain, one per day). It will 
 *then print the following statistics.
 *	i. Number of days that were read in.
 *	ii. Total rainfall.
 *	iii. Average rainfall per day. Compute this as a floating point number.
 *	iv. Maximum. The largest amount of rain that fell in any one day.
 *	Hint: Use the JOptionPane.showInputDialog() to accept each rainfall 
 *measurement.  You can also use the JOptionPane.showConfirmDialog() to control the 
 *flow of the input.
 *
 * 
 */
public class Rainfall {

    public static void main(String args[]) {
       //declare variable
        int day = 0;
        double sum = 0;
        double max = 0;
        double rainfall = 0;
        int reply = 0;

        do {
            //get rainfall
            rainfall = Double.valueOf(JOptionPane.showInputDialog(null, "Enter rainfall"));
           
            //add to total
            sum = sum + rainfall; //sum+=rainfall;
            //day +1
            day++;
            //if new rainfall is bigger than current max
            if (max < rainfall) {
                max = rainfall;
            }
           
            System.out.println(rainfall);

            //ask if wants to get another reading
            reply = JOptionPane.showConfirmDialog(null, "Add another rainfall measurement", "Rainfall", JOptionPane.YES_NO_OPTION);

        } while (reply == JOptionPane.YES_OPTION);

        //prints total day, sum, ave, max
        System.out.println("Total days = " + day);
        System.out.println("Total rainfall = " + sum);
        System.out.println("Average rainfall = " + (sum / day));
        System.out.println("Maximum rainfall = " + max);

    }
}
